package com.wbp.cms.qatest.dao;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

import com.wbp.cms.client.user.domain.UserDO;
import com.wbp.cms.client.user.query.UserQuery;
import com.wbp.cms.client.util.DateUtils;
import com.wbp.cms.client.util.MD5Utils;
import com.wbp.cms.core.user.dao.UserDAO;
import com.wbp.cms.qatest.BaseTest;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月6日 下午10:46:48
 */
public class UserDAOTest extends BaseTest {

  @Resource
  private UserDAO userDAO;

  @Test
  public void test_新增() {

    UserDO userDO = new UserDO();
    userDO.setUserName("lihc-001");
    userDO.setPwd("111111");
    try {
      userDO.setBirthday(DateUtils.parse("1987-08-07", DateUtils.ISO_DATE_FORMAT).toString());
    } catch (ParseException e) {
      e.printStackTrace();
    }
    userDO.setImage("http://localhost:8888/111.png");
    userDO.setNickName("nickname-002");
    userDO.setMobileNumber("15093492234");
    userDO.setGender(2);
    userDO.setRealName("real001");
    userDO.setAddress("武汉市武昌洪山区");
    System.out.println(userDAO.insert(userDO) > 0);
  }


  @Test
  public void test_修改() {

    UserDO userDO = new UserDO();
    userDO.setId(1L);

    userDO.setUserName("lihc-002");
    userDO.setPwd("111111");
    userDO.setImage("http://localhost:8888/111.png");
    userDO.setNickName("nickname-002");
    userDO.setMobileNumber("15093492234");
    userDO.setGender(1);
    userDO.setIdCard("333333333333333");
    userDO.setRealName("real001");
    userDO.setAddress("武汉市武昌洪山区");
    userDO.setOrganizationId(1L);
    System.out.println(userDAO.update(userDO) == 1);
  }

  @Test
  public void test_load() {
    UserDO userDO = userDAO.load(2L);
    System.out.println(userDO);
  }

  @Test
  public void test_查询() {
    UserQuery userQuery = new UserQuery();
    userQuery.setAddress("武汉市武昌");
    userQuery.setUserName("lihc");
    List<UserDO> userDO = userDAO.query(userQuery);
    System.out.println("userDO: " + userDO);
  }

  @Test
  public void test_查询数量() {
    UserQuery userQuery = new UserQuery();
    // userQuery.setAddress("武汉市武昌");
    // userQuery.setUserName("lihc");
    userQuery.setRealName("real");
    Integer count = userDAO.queryCount(userQuery);
    System.out.println("userDO count: " + count);
  }
  
  @Test
  public void test_查询2() {
    
    UserDO user = userDAO.queryUserByUserName("18971612470") ;
    System.out.println("userDO user: " + user);
  }
  
  @Test
  public void test_md5pwd(){
     String userName="lihc-003" ;
     String passWord ="111111" ;
     try {
      passWord = MD5Utils.strToMD5(passWord + userName);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
     System.out.println(passWord);
  }
  
}
